<?php
$this->pageTitle = Yii::app()->name;
$this->breadcrumbs=array(
	'采购',
);
include_once('menu.php');
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => '.update', 'config' => array('width' => 830, 'height' => 520,'type'=>'iframe','hideOnOverlayClick'=>false)));
Yii::import('ext.qtip.QTip');
QTip::qtip('span[title]');
?>
<div style="width:100%; float:left; margin-bottom:10px; text-align:right;">
	<form action="" name="jobForm" id="jobForm" method="get">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="13%" class="td_right"><?php echo $labels['OrderName']; ?>: </td>
			<td width="20%"><input type="text" name="OrderName" value="<?php if(isset($search['OrderName']))echo $search['OrderName'];?>" id="OrderName" class="input_size" /></td>
			<td width="14%" class="td_right"><?php echo $labels['ProductModel']; ?>: </td>
			<td width="20%"><input type="text" name="ProductModel" value="<?php if(isset($search['ProductModel']))echo $search['ProductModel'];?>" id="ProductModel" class="input_size" /></td>
			<td width="13%" class="td_right"><?php echo $labels['Buyer']; ?>: </td>
			<td><input type="text" name="Buyer" value="<?php if(isset($search['Buyer']))echo $search['Buyer'];?>" id="Buyer" class="input_size" /></td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $labels['Date']; ?>: </td>
			<td><input type="text" name="Date" id="Date" value="<?= $search['Date'] ?>" readonly="readonly" style="width:95px;" />
		<img onclick="displayCalendar(document.jobForm.Date,'yyyymmdd',this)" style="cursor:pointer;" width="25" src="images/calendar.png" /></td>
			<td class="td_right"><?php echo $labels['ProductDetail']; ?>: </td>
			<td><input type="text" name="ProductDetail" value="<?php if(isset($search['ProductDetail']))echo $search['ProductDetail'];?>" id="ProductDetail" class="input_size" /></td>
			<td class="td_right"><?php echo $labels['ToLAMethod']; ?>: </td>
			<td><?php echo CHtml::dropDownList('ToLAMethod',$search['ToLAMethod'], Yii::app()->params['method'],array('empty'=>array(''=>'请选择'),'class'=>'input_size7'));?></td>
		</tr>
		<tr>			
			<td class="td_right"><?php echo $labels['Event']; ?>: </td>
			<td><?php echo CHtml::dropDownList('Event',$search['Event'], Yii::app()->params['event'],array('empty'=>array(''=>'请选择'),'class'=>'input_size7'));?></td>
			<td class="td_right"><?php echo $labels['Destination1']; ?>: </td>
			<td><input type="text" name="Destination1" value="<?php if(isset($search['Destination1']))echo $search['Destination1'];?>" id="Destination1" class="input_size" /></td>
			<td class="td_right"><?php echo $labels['Destination2']; ?>: </td>
			<td><input type="text" name="Destination2" value="<?php if(isset($search['Destination2']))echo $search['Destination2'];?>" id="Destination2" class="input_size" /></td>
		</tr>
		<tr>			
			<td colspan="6" style="text-align:right;"><a style="margin-right:50px;" href="<?=Yii::app()->createUrl('psi/AddTrackingItem',array('trackingIndex'=>$_REQUEST['trackingIndex']))?>"><img src="images/shua.png" border="0" /></a><input type="image" src="images/go.png" name="jobSub" id="jobSub" value="Go" /></td>			
		</tr>
	</table>		
		<input type="hidden" name="r" value="psi/AddTrackingItem" />
		<input type="hidden" name="trackingIndex" value="<?=$_REQUEST['trackingIndex']?>" />
	</form>
</div>
<form name='multi' id="multi" method="post">
<table cellspacing="0" cellpadding="0" width="100%" class="tbl" style="float:left;">
	<tr class="head">
		<td width="2%"><input type="checkbox" name="checkAll" id="checkAll"></td>
		<td width="10%"><?php echo $labels['Date']; ?></td>
		<td width="10%"><?php echo $labels['ProductModel']; ?></td>
		<td width="25%"><?php echo $labels['ProductDetail']; ?></td>
		<td width="6%"><?php echo $labels['PQuantity']; ?></td>
		<td width="8%">未出货数量</td>
		<td width="10%"><?php echo $labels['Destination1']; ?></td>
		<td><?php echo $labels['ToLAQty']; ?></td>		
		<?php
		if($model->ShippingType=='Container'){
		?>
		<td width="20%">箱号</td>
		<?php
		}
		?>		
	</tr>
	<?php
    $i = 0;
    $cssArr = array(0 => 'even', 1 => 'odd', 2 => 'three');
    foreach ($rowTable as $item) {
        $trClass = $cssArr[$i % 3];
        $i++;
        ?>
	<tr class="<?= $trClass ?>">
		<td style="text-align:center;"><input type="checkbox" name="PricingIndexs[]" id="<?=$item->PricingIndex?>" value="<?=$item->PricingIndex?>"></td>
		<td>
			<?=$item->Date?>
		</td>
		<td>
			<?=$item->ProductModel?>
		</td>
		<td>
			<span title="<span style='line-height:20px; font-size:12px;'><?=$item->ProductDetail?></span>"><?=Helper::truncate_utf8_string($item->ProductDetail,15,'')?></span>
		</td>
		<td style="text-align:center;">
			<?=$item->PQuantity?>
		</td>
		<td style="text-align:center;">
			<?=$item->Balance-$item->ToLAQty?>
		</td>
		<td style="text-align:center;">
			<?=$item->Destination1?>
		</td>
		<td style="text-align:center;">
			<?php echo CHtml::textField('ToLAQty_'.$item->PricingIndex,$_POST['ToLAQty_'.$item->PricingIndex],array('style'=>'width:50px;')); ?>
		</td>		
		<?php
		if($model->ShippingType=='Container'){
		?>
		<td style="text-align:center;">
			<?php echo CHtml::textField('BoxNum_'.$item->PricingIndex,$_POST['BoxNum_'.$item->PricingIndex],array('style'=>'width:120px;')); ?>
		</td>
		<?php
		}
		?>		
	</tr>
	<?php
    }
    ?>
</table>
<div id="pager" align="center">
<?php  
	$this->widget('CLinkPager',array(  
		'header'=>'',  
		'firstPageLabel' => '<<',
		'lastPageLabel' => '>>',
		'prevPageLabel' => '<',
		'nextPageLabel' => '>',
		'pages' => $pages,  
		'maxButtonCount'=>13  
		));  
?>
</div>
<div style="width:100%; float:left; margin-top:10px; text-align:center;">
	<div style="text-align:center;"><input type="button" onclick="fxl()" name="multiSub" value="关联" /></div>	
</div>
</form>
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
$(document).on('click','#checkAll',function() {
	var checked=this.checked;
	$("input[name='PricingIndexs\[\]']").each(function() {this.checked=checked;});
});
$(document).on('click', "input[name='PricingIndexs\[\]']", function() {
	$('#PricingIndexs').prop('checked', $("input[name='PricingIndexs\[\]']").length==$("input[name='PricingIndexs\[\]']:checked").length);
});
});
function fxl(){
	var val = false;
	$("input:checkbox[name='PricingIndexs\[\]']").each(function (){
    	if($(this).attr("checked")=='checked'){
			val = true;
        }
    });
	if(!val){
		alert('请选择需要关联的产品');
		return false;
	}
<?php
foreach ($rowTable as $item) {
?>
	if($("#<?=$item->PricingIndex?>").is(":checked")){
		if(parseInt($('#ToLAQty_<?=$item->PricingIndex?>').val())>parseInt('<?=Helper::getAbleNumByPricingIndex($item->PricingIndex)?>')){
			$('#ToLAQty_<?=$item->PricingIndex?>').focus();
			alert('运出数量不能大于可运出数量')
			return false;
		}
		if(parseInt($('#ToLAQty_<?=$item->PricingIndex?>').val())<=0 || $('#ToLAQty_<?=$item->PricingIndex?>').val()==''){
			$('#ToLAQty_<?=$item->PricingIndex?>').focus();
			alert('请输入运出数量')
			return false;
		}
	}
<?php
}
?>
	document.forms.multi.submit();
}
/*]]>*/
</script>